package course.dao.impl;

import course.dao.AdminDao;
import course.dao.BaseDao;
import course.pojo.entity.Admin;

import java.sql.Connection;
import java.util.List;

/**
 * @author HLF
 * @date 2022/6/30 19:46
 */
public class AdminDaoImpl extends BaseDao<Admin> implements AdminDao {

    @Override
    public Admin getById(Integer aid, Connection connection) {
        String sql = "select * from t_admin where aid = ?;";
        return getOneBean(connection, sql, aid);
    }

    @Override
    public int addAdmin(Admin admin, Connection connection) {
        String sql = "insert into t_admin values(?,?,?,?);";
        return insert(connection, sql, admin.getAid(), admin.getAuser(), admin.getApassword(), admin.getAtar());
    }

    @Override
    public int updateById(Admin admin, Connection connection) {
        String sql = "update t_admin set auser = ?,apassword = ?,atar = ? where aid = ?";
        return update(connection, sql, admin.getAuser(), admin.getApassword(), admin.getAtar(), admin.getAid());
    }

    @Override
    public int deleteById(Integer aid, Connection connection) {
        String sql = "delete from t_admin where aid = ?";
        return update(connection, sql, aid);
    }

    @Override
    public List<Admin> getList(Connection connection) {
        String sql = "select * from t_admin";
        return getBeanList(connection, sql);
    }

    @Override
    public Admin getByAuser(String auser, Connection connection) {
        String sql = "select * from t_admin where auser = ?;";
        return getOneBean(connection, sql, auser);
    }
}
